package com.algorithm.base.backtracking;

import java.util.ArrayList;
import java.util.List;

/**
 * 电话号码的字母组合
 *
 * @author Amadeus
 * @date 2023/10/31
 */
public class LetterCombinations {

    static String[] phoneNumber = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};

    public static List<String> letterCombinations(String digits) {
        List<String> result = new ArrayList<>();
        if (digits.isEmpty()) {
            return result;
        }
        backTracking(0, digits, result, "");
        return result;
    }

    public static void backTracking(int index, String digits, List<String> result, String current) {
        if (index == digits.length()) {
            result.add(current);
            return;
        }
        String letters = phoneNumber[digits.charAt(index) - '0'];
        for (char c : letters.toCharArray()) {
            backTracking(index + 1, digits, result, current + c);
        }
    }

    public static void main(String[] args) {
        System.out.println(letterCombinations(""));
    }

}
